package org.jeecg.modules.simulator.vo;

import lombok.Data;
import org.jeecg.modules.simulator.model.orbit.OrbitPoint;

import java.math.BigDecimal;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @program: simulator-b20240918
 * @description:
 * @author: renzhg
 * @create: 2024-10-04 13:37
 **/
@Data
public class TrainPosition implements Comparable<TrainPosition>{

    Integer index;
    String  belongingType;
    String  orbitName;
    String lineId;
    Long startOffsetDistance;
    Long endOffsetDistance;
    Long currentOpt;
    String orbitId;
    BigDecimal positionRatio;//
    String trainId;
    String trainNum;
    String curTime;

    public void setOrbitAttr(OrbitPoint orbitPoint,String tableItemName,String itemId) {
        this.index = orbitPoint.getIndex();
        this.belongingType = orbitPoint.getBelongingType();
        if(belongingType.equals("station")){
            this.orbitName = tableItemName;

        }else{
            this.orbitName = orbitPoint.getOrbitName();
        }

//        this.orbitName = orbitPoint.getOrbitName();
        this.lineId = orbitPoint.getLineId();
        this.startOffsetDistance = orbitPoint.getStartOffsetDistance();
        this.endOffsetDistance = orbitPoint.getEndOffsetDistance();
        this.orbitId=itemId;

    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("TrainPosition{");
        sb.append("index=").append(index);
        sb.append(", belongingType='").append(belongingType).append('\'');
        sb.append(", orbitName='").append(orbitName).append('\'');
        sb.append(", lineId='").append(lineId).append('\'');
        sb.append(", startOffsetDistance=").append(startOffsetDistance);
        sb.append(", endOffsetDistance=").append(endOffsetDistance);
        sb.append(", currentOpt=").append(currentOpt);
        sb.append(", orbitId='").append(orbitId).append('\'');
        sb.append(", positionRatio=").append(positionRatio);
        sb.append(", trainId='").append(trainId).append('\'');
        sb.append(", trainNum='").append(trainNum).append('\'');
        sb.append(", curTime='").append(curTime).append('\'');
        sb.append('}');
        return sb.toString();
    }

    @Override
    public int compareTo(TrainPosition other) {
        // 使用 LocalTime.parse 来比较 curTime 字段
        LocalTime thisTime = LocalTime.parse(this.curTime, DateTimeFormatter.ofPattern("HH:mm:ss"));
        LocalTime otherTime = LocalTime.parse(other.curTime, DateTimeFormatter.ofPattern("HH:mm:ss"));
        return thisTime.compareTo(otherTime);
    }
}
